package com.xxmw.transaction.task;

import com.xxmw.transaction.controller.server.TransactionWebsocketServer;
import com.xxmw.transaction.enumeration.TopicEnum;
import com.xxmw.transaction.service.robot.RobotOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ctc挂单量消息推送
 * @author luowenliang
 * @since 2020/3/12 11:21
 */
@Slf4j
@Component
public class CtcOrderNumTask {

    @Autowired
    private RobotOrderService robotOrderService;

    @Scheduled(cron = "0/6 * *  * * ? ")
    public void push() {
        Map<String, Object> map = robotOrderService.ctcOrderNumCount();
        ConcurrentHashMap<Long, TransactionWebsocketServer> serverMap = TransactionWebsocketServer.getServer();
        if (!serverMap.isEmpty()) {
            serverMap.forEach((id, server) -> {
                //订阅了发送消息
                if (server.isSubscribed(TopicEnum.SYMBOL_CTC_ORDER_NUM_TOPIC.getDesc())) {
                    server.senObject(map);
                }
            });
        }
    }
}
